package redlib.backend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redlib.backend.annotation.BackendModule;
import redlib.backend.annotation.NeedNoPrivilege;
import redlib.backend.annotation.Privilege;
import redlib.backend.dto.BioinformaticDocDTO;
import redlib.backend.dto.query.BioinformaticDocQueryDTO;
import redlib.backend.dto.query.KeywordQueryDTO;
import redlib.backend.model.Page;
import redlib.backend.service.BioinformaticDocService;
import redlib.backend.vo.BioinformaticDocVO;
import redlib.backend.vo.LuceneResultBookVO;

import java.util.List;

/**
 * 文献管理后端服务模块
 *
 * @author Zane
 * @description
 */

@RestController
@RequestMapping("/api/bioinformaticDoc")
@BackendModule({"page:页面", "update:修改", "add:创建", "delete:删除"})
public class BioinformaticDocController {
    @Autowired
    private BioinformaticDocService bioinformaticDocService;

    @PostMapping("listBioinformaticDoc")
    @Privilege("page")
    public Page<BioinformaticDocVO> listBioinformaticDoc(@RequestBody BioinformaticDocQueryDTO queryDTO) {
        return bioinformaticDocService.listByPage(queryDTO);
    }

    @PostMapping("addBioinformaticDoc")
    @Privilege("add")
    public Integer addBioinformaticDoc(@RequestBody BioinformaticDocDTO bioinformaticDocDTO) {
        return bioinformaticDocService.addBioinformaticDoc(bioinformaticDocDTO);
    }

    @PostMapping("updateBioinformaticDoc")
    @Privilege("update")
    public Integer updateDepartment(@RequestBody BioinformaticDocDTO bioinformaticDocDTO) {
        return bioinformaticDocService.updateBioinformaticDoc(bioinformaticDocDTO);
    }

    @PostMapping("deleteBioinformaticDoc")
    @Privilege("delete")
    public void deleteBioinformaticDoc(@RequestBody List<Integer> ids) {
        bioinformaticDocService.deleteByCodes(ids);
    }

    @PostMapping("getBioinformaticDocByCode")
    @NeedNoPrivilege
    public String getBioinformaticDocByCode() {
        return "Hello,world";
    }

    @PostMapping("fullSearch")
    @Privilege("page")
    public Page<LuceneResultBookVO> search(@RequestBody KeywordQueryDTO queryDTO) {
        return bioinformaticDocService.search(queryDTO);
    }
}
